
local MainScene = class("MainScene", cc.load("mvc").ViewBase)

function MainScene:onCreate()
    local enemy = display.newSprite("enemy.png")
        :move(display.cx, display.cy)
        :addTo(self)

    local player = display.newSprite("player.png")
        :move(0, display.cy)
        :addTo(self)
    player:runAction(cc.MoveTo:create(6, cc.p(display.width, display.cy)))

    local scheduler = self:getScheduler()
    scheduler:scheduleScriptFunc(function()
        local rectA = player:getBoundingBox()
        local rectB = enemy:getBoundingBox()
        if cc.rectIntersectsRect(rectA, rectB) then
            if nil == player:getActionByTag(10) then
                local blink = cc.Blink:create(0.05, 2)
                blink:setTag(10)
                player:runAction(blink)
            end
        else
            if player:getActionByTag(10) then
                player:stopActionByTag(10)
            end
        end
    end, 0.3, false)
end

return MainScene
